package com.neuedu.service.impl;

import com.neuedu.service.AiServiceCommon;
import com.neuedu.service.Assistant;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class AiServiceCommonImpl implements AiServiceCommon {
    @Resource(name = "qwen-plus")
    ChatModel chatModel;
    @Resource(name = "wycharstorage")
    ChatMemoryStore chatMemoryStore;
    public Assistant getAssistant(Long login_id, String sessionId) {
        MessageWindowChatMemory build = MessageWindowChatMemory.builder()
                .id(login_id + "::" + sessionId)
                .chatMemoryStore(chatMemoryStore)
                .maxMessages(10)
                .build();
        return AiServices.builder(Assistant.class)
                .chatModel(chatModel)
                .chatMemoryProvider(memoryId -> build)
                .build();
    }
}
